import { XRequest } from "@ant-design/x";
import { useDispatch, useSelector } from "react-redux";
const BASE_URL = "http://172.16.1.118:7861";
const PATH = "/chat/chat";

import token from '@/api/token'
async function mockFetch(url, config) {

  const params = JSON.parse(config.body);
  console.log(params)
  const requestData = {
    stream: true,
    conversation_id: params.messages[0].chatId,
    history_len: 0,
    max_tokens: 0,
    model_name: "Qwen1.5-14B-Chat",
    prompt_name: "default",
    query: params.messages[0].content,
    temperature: 0.7,
    user_id: 356,
  };
  const response: Response = await fetch(BASE_URL + PATH, {
    method: "POST",
    headers: {
        Authorization: `Bearer ${localStorage.getItem("react_token")}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(requestData),
  });
  return response;
}
const fetchChat = XRequest({
  baseURL: BASE_URL + PATH,
  fetch: mockFetch,
});

export { fetchChat };